home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / BORL_TIP / TI1000 / TI1725.ASC < prev    next >
Text File  |  1994-10-03  |  2KB  |  111 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.   PRODUCT  :  Pascal                                 NUMBER  :  1725
  8.   VERSION  :  All
  9.        OS  :  DOS
  10.      DATE  :  September 30, 1994                       PAGE  :  1/2
  11.  
  12.     TITLE  :  Turbo Vision local menu using right mouse button
  13.  
  14.  
  15.  
  16.  
  17.  
  18. This is an example Turbo Vision program that demonstrates using
  19. local menus that are activated with the right mouse button
  20. and are positioned on screen by the mouse position.
  21.  
  22. program Localmenu;
  23. uses
  24.   Drivers, Objects, Views, App, Menus;
  25.  
  26. const
  27.   cmNothing = 101;
  28. type
  29.  
  30.   TMyApp = object(TApplication)
  31.     LocalMenu: PMenu;
  32.     LocalMenuOpen: boolean;
  33.     constructor Init;
  34.     procedure GetEvent(var Event: TEvent); virtual;
  35.   end;
  36.  
  37. constructor TMyApp.Init;
  38. begin
  39.   inherited Init;
  40.   LocalMenu :=  NewMenu(
  41.     NewItem('Item~1~', '', 0, cmNothing, hcNOContext,
  42.     NewItem('Item~2~', '', 0, cmNothing, hcNoContext,
  43.     nil)));
  44.   LocalMenuOpen := false;
  45.   EventMask := EventMask or evBroadcast;
  46. end;
  47.  
  48. procedure TMyApp.GetEvent(var Event: TEvent);
  49. var
  50.   MousePt: TPoint;
  51.   R: TRect;
  52.   Box: PMenuBox;
  53.   NewEvent: TEvent;
  54.   Code: Word;
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.   PRODUCT  :  Pascal                                 NUMBER  :  1725
  68.   VERSION  :  All
  69.        OS  :  DOS
  70.      DATE  :  September 30, 1994                       PAGE  :  2/2
  71.  
  72.     TITLE  :  Turbo Vision local menu using right mouse button
  73.  
  74.  
  75.  
  76.  
  77. begin
  78.   inherited GetEvent(Event);
  79.   if ((Event.What = evMouseDown) AND (Event.Buttons =
  80.           mbRightButton) AND NOT LocalMenuOpen)
  81.   then
  82.   begin
  83.     LocalMenuOpen := true;
  84.     MousePt := Event.Where;
  85.     if (MousePt.X > 70) then MousePt.X := 70;
  86.     if (MousePt.Y > 20) then MousePt.Y := 20;
  87.     ClearEvent(Event);
  88.     R.Assign(MousePt.X, MousePt.Y, MousePt.X+11, MousePt.Y+2);
  89.     Box := new(PMenuBox, Init(R, LocalMenu, nil));
  90.     Code := ExecView(Box);
  91.     Dispose(Box);
  92.     LocalMenuOpen := false;
  93.     NewEvent.What := evBroadcast;
  94.     NewEvent.Command := code;
  95.     PutEvent(NewEvent);
  96.   end;
  97. end;
  98. var
  99.   MyApp: TMyApp;
  100. begin
  101.   MyApp.Init;
  102.   MyApp.Run;
  103.   MyApp.Done;
  104. end.
  105.  
  106.  
  107. DISCLAIMER: You have the right to use this technical information
  108. subject to the terms of the No-Nonsense License Statement that
  109. you received with the Borland product to which this information
  110. pertains.
  111.